package com.common.boot.generator;

import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class BatchQuery {
  public static void main(String[] args) throws InterruptedException {
    int threadNum = 5;
    int pdcount = 100000;
    pdcount = pdcount + 100; // 多+100 防止少查数据
    System.out.println("共有" + pdcount + "条数据");
    String qdm = "310115";
    // 分片
    int partNum = (pdcount / threadNum);
    ConcurrentLinkedDeque<String> sqlList = new ConcurrentLinkedDeque<>();

    System.out.println("每个线程要处理的数量=" + (pdcount / threadNum));
    ExecutorService executorService = Executors.newFixedThreadPool(threadNum);
    for (int i = 0; i < threadNum; i++) {
      int finalI = i;
      executorService.execute(
          () -> {
            int tPreIndex = (finalI * partNum);
            int tNextIndex = (partNum * (finalI + 1));
            String jbxxSql =
                "select * from (select * "
                    + " from t_fwjbxx where QDM = '"
                    + qdm
                    + "' ) where num > "
                    + tPreIndex
                    + "  and num < "
                    + tNextIndex;
            sqlList.add(jbxxSql);
          });
    }

    for (String s : sqlList) {
      System.out.println(s);
      Thread.sleep(700L);
    }
    System.out.println(sqlList);
  }
}
